/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.bigstorage.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.bigstorage.entity.Category;
import com.jeesite.modules.bigstorage.service.CategoryService;

/**
 * 分类表Controller
 * @author zhuqingya
 * @version 2019-12-13
 */
@Controller
@RequestMapping(value = "${adminPath}/bigstorage/category")
public class CategoryController extends BaseController {

	@Autowired
	private CategoryService categoryService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Category get(String id, boolean isNewRecord) {
		return categoryService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("bigstorage:category:view")
	@RequestMapping(value = {"list", ""})
	public String list(Category category, Model model) {
		model.addAttribute("category", category);
		return "modules/bigstorage/categoryList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("bigstorage:category:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Category> listData(Category category, HttpServletRequest request, HttpServletResponse response) {
		category.setPage(new Page<>(request, response));
		Page<Category> page = categoryService.findPage(category);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("bigstorage:category:view")
	@RequestMapping(value = "form")
	public String form(Category category, Model model) {
		model.addAttribute("category", category);
		return "modules/bigstorage/categoryForm";
	}

	/**
	 * 保存分类表
	 */
	@RequiresPermissions("bigstorage:category:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Category category) {
		categoryService.save(category);
		return renderResult(Global.TRUE, text("保存分类表成功！"));
	}
	
	/**
	 * 删除分类表
	 */
	@RequiresPermissions("bigstorage:category:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(Category category) {
		categoryService.delete(category);
		return renderResult(Global.TRUE, text("删除分类表成功！"));
	}
	
}